$(function () {
    var winWidth = $(window).width();
    //Initiat WOW JS
    new WOW({animateClass: 'animated'}).init();
    //smoothScroll
    smoothScroll.init();


    var mapText = ['公司介绍', '员工风采', '招贤纳士', '联系我们'];

    var testSwiper = new Swiper('.banner-swiper-container', {
        pagination: {
            el: '.banner-swiper-pagination',
            clickable: true,
            renderBullet: function (index, className) {
                return '<div class="swiper-pagination-customs ' + className + '"><span class="pagiCont">' + mapText[index] + '</span></div>';
            },
        },
        on: {
            init: function () {
                swiperAnimateCache(this); //隐藏动画元素
                swiperAnimate(this); //初始化完成开始动画
            },
            slideChangeTransitionEnd: function () {
                swiperAnimate(this); //每个slide切换结束时也运行当前slide动画
            },
            slideChange: function () {
                $('.tab-item').addClass('hide').eq(this.activeIndex).removeClass('hide');

                $('.foot-nav-item li').removeClass('active').eq(this.activeIndex).addClass('active');
                //解决进入员工风采时，轮播分页不法显示的问题,在这里切换时触发点击事件
                if (this.activeIndex == 1) {
                    $('.staff-foot-item').eq(0).click();
                }
            }
        },
        lazy: {
            loadPrevNext: false,
        }
    });

    if(winWidth > 767){
        $('.foot-nav-item li').on('click',function () {
            var idx = $(this).index();
            testSwiper.slideTo(idx);
        });

        $('.foot-nav-right span').on('mouseenter',function () {
            var idx = $(this).index();
            $('.foot-nav-right img').addClass('hide').eq(idx).removeClass('hide');
        })

        $('.foot-nav-right span').on('mouseleave',function () {
            var idx = $(this).index();
            $('.foot-nav-right img').eq(idx).addClass('hide');
        })
    }

    //加入我们查看详情按钮点击事件
    $('.detail-btn').on('click',function () {
        testSwiper.slideTo(2);
    })


   if(winWidth > 768){
       //地图初始化时，在地图上添加一个marker标记,鼠标点击marker可弹出自定义的信息窗体
       var map = new AMap.Map("map-container", {
           resizeEnable: true,
           center: [121.380277,31.189759],
           zoom: 16
       });
       addMarker();

       //添加marker标记
       function addMarker() {
           map.clearMap();
           var marker = new AMap.Marker({
               map: map,
               position: [121.380277,31.189759]
           });
           //鼠标点击marker弹出自定义的信息窗体
           AMap.event.addListener(marker, 'click', function () {
               infoWindow.open(map, marker.getPosition());
           });
       }

       //增加控制栏
       map.plugin(["AMap.ToolBar"], function () {
           map.addControl(new AMap.ToolBar());
       });
       //实例化信息窗体
       var title = '联系我们',
           content = [];
       content.push("地址：上海市延安西路3062弄18号1楼");
       content.push("邮箱：admin@yoya.cn");
       content.push("电话：021-62950688");
       var infoWindow = new AMap.InfoWindow({
           isCustom: true,  //使用自定义窗体
           content: createInfoWindow(title, content.join("<br/>")),
           offset: new AMap.Pixel(16, -45)
       });
   }

    //构建自定义信息窗体
    function createInfoWindow(title, content) {
        var info = document.createElement("div");
        info.className = "info";

        //可以通过下面的方式修改自定义窗体的宽高
        //info.style.width = "400px";
        // 定义顶部标题
        var top = document.createElement("div");
        var titleD = document.createElement("div");
        var closeX = document.createElement("img");
        top.className = "info-top";
        titleD.innerHTML = title;
        closeX.src = "http://webapi.amap.com/images/close2.gif";
        closeX.onclick = closeInfoWindow;

        top.appendChild(titleD);
        top.appendChild(closeX);
        info.appendChild(top);

        // 定义中部内容
        var middle = document.createElement("div");
        middle.className = "info-middle";
        middle.style.backgroundColor = 'white';
        middle.innerHTML = content;
        info.appendChild(middle);

        // 定义底部内容
        var bottom = document.createElement("div");
        bottom.className = "info-bottom";
        bottom.style.position = 'relative';
        bottom.style.top = '0px';
        bottom.style.margin = '0 auto';
        var sharp = document.createElement("img");
        sharp.src = "http://webapi.amap.com/images/sharp.png";
        bottom.appendChild(sharp);
        info.appendChild(bottom);
        return info;
    }

    //关闭信息窗体
    function closeInfoWindow() {
        map.clearInfoWindow();
    }

})
